<template>
    <div class='home-Singer'>
        <h3>热门歌手</h3>
        <div class="wrapper" ref="wrapper">
            <!-- 滚动所需的容器 -->
            <ul class="content" ref="content">
                <li v-for="(item, index) in listData" :key="index" @click="selectItem(item)">
                    <div class=" cover">
                        <van-image :src="item.singer_pic" radius="1rem" />
                        <!-- <span>{{item.listen_num | numFilter(1)}}万</span> -->
                    </div>
                    <span>{{ item.singer_name }}</span>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
import { betterScrollHorizontal } from "../../common/betterScroll.js"; //引入betterscroll
export default {
    data() {
        return {
            listData: [],
        }
    },
    created() {
        this.getData()
    },
    methods: {
        getData() {
            this.$request('get', "/singer/list").then((res) => {
                console.log(res);
                if (res.result == 100) {
                    this.listData = res.data.list;
                }
                betterScrollHorizontal(
                    this,
                    this.$refs.wrapper,
                    this.$refs.content,
                    this.listData.length,
                    10
                )
            })
        },
        //列表项的点击事件
        selectItem(item) {
            const singermid = item.singer_mid;//歌手的id
            //1调用状态管理，commit提交唤醒mutations
            // this.$store.commit('saveSinger', item)
            //2调用状态管理，通过分发action方法，通过dispatch
            this.$store.dispatch("saveSinger", item)
            this.$router.push(`/singer/${singermid}`);
        }
    },
}
</script>

<style scoped>
.cover {
    position: relative;
}

.cover>span {
    position: absolute;
    right: 0.2rem;
    bottom: 0.4rem;
    background-color: #a6a0a0;
    color: white;
    font-size: 14px;
    border-radius: 1rem;
    width: 5rem;
    display: inline-block;
}

.wrapper {
    width: 100%;
    /* 容器的宽度就是屏幕的宽度 */
    overflow: hidden;
}

/* ul.content {
     content内容去的宽度要大于wrapper容器的宽度，12个列表项 
    width: calc(12*10rem);
} */

ul.content li {
    /* li默认是块级元素，修改行内元素，但是要具备块级元素的特性 */
    display: inline-block;
    width: 10rem;
    vertical-align: top;

}

/* li里面又两个元素：div和span,所以使用通配符 */
ul.content li * {
    margin: 0.1rem;
    /* 里面的元素与li的边缘有个间距 */
}

ul.content li>span {
    font-size: 0.8rem;
    color: #54493b;
}
</style>